package com.ai.consumer.service;

import com.ai.consumer.dao.ConsumerMapper;
import com.ai.consumer.model.Consumer;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Date:  2018/11/1
 * Time:  14:23
 * Email: siy@hmgsoft.com
 * Created by siy
 */
@Service
public class ConsumerServiceImpl implements ConsumerService {
    @Resource
    private ConsumerMapper consumerMapper;

    @Override
    public Consumer sel(Consumer consumer) {
        return consumerMapper.selectOne(consumer);
    }

    @Override
    public List<Consumer> selAll(Consumer consumer) {
        PageHelper.startPage(1,10);
        List<Consumer> consumers = consumerMapper.select(consumer);
        PageInfo pageInfo = new PageInfo(consumers);
        return pageInfo.getList();
    }

    @Transactional
    @Override
    public int add(Consumer consumer) {
        return consumerMapper.insertSelective(consumer);
    }
}
